package tpi.gui.carmensd.ui

import android.app.Activity
import org.eclipse.xtend.lib.annotations.Accessors
import tpi.gui.carmensd.dto.Villano
import android.os.Bundle
import tpi.gui.carmensd.R
import android.widget.RelativeLayout
import tpi.gui.carmensd.service.CarmenSandiegoService
import tpi.gui.carmensd.utils.Utils
import retrofit.Callback
import retrofit.RetrofitError
import retrofit.client.Response

@Accessors
class PantallaFinalActivity extends Activity {
	
	CarmenSandiegoService service
	extension Utils = new Utils
	
	override onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState)
		setContentView(R.layout.activity_pantalla_final)
		
		service = createService()
		decidirFinal()
	}
	
	def decidirFinal() {
		service.getGano(new Callback<Boolean>() {
			override failure(RetrofitError e) {
				e.printStackTrace()
			}
			override success(Boolean gano, Response response) {
				if (gano) pantallaGano() else pantallaPerdio()
			}
		})
	}
	
	def pantallaGano() {
		findViewById(R.id.layout_final) as RelativeLayout=> [
			backgroundResource = R.drawable.ganaste	
		]
	}
	
	def pantallaPerdio() {
		findViewById(R.id.layout_final) as RelativeLayout=> [
			backgroundResource = R.drawable.perdiste	
		]
	}
}